package com.hnucm.cooklife.model;

import com.hnucm.cooklife.base.BaseModel;
import com.hnucm.cooklife.bean.db.Work;
import com.hnucm.cooklife.contract.me.Contract;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;

public class MeWorkModel extends BaseModel implements Contract.IMeWorkModel {
    public MeWorkModel() {
        setCookies(false);
    }

    @Override
    public Observable<List<Work>> loadMyWork(int userId) {
        return mApiServer.loadWorks(userId)
                .map(meData -> {
                    List<Work> workList = new ArrayList<>();
                    meData.getData().stream().forEach(dataDTO -> {
                        Work work = new Work();
                        work.workId = dataDTO.getWorkId();
                        work.workDesc = dataDTO.getWorkDesc();
                        work.workPic = dataDTO.getWorkPic();
                        work.dishId = dataDTO.getDishId();
                        work.userId = dataDTO.getUserId();
                        workList.add(work);
                    });
                    return workList;
                });
    }

    @Override
    public Observable<List<Work>> refreshMyWork(int userId) {
        return loadMyWork(userId);
    }
}
